package com.ruoyi.dataserver.controller;

import com.ruoyi.dataserver.api.dto.StatisticDto;
import com.ruoyi.dataserver.api.dto.StatisticResultDTO;
import com.ruoyi.dataserver.config.ScConfigAddress;
import com.ruoyi.dataserver.service.ISegmentationService;
import com.ruoyi.dataserver.utils.CommonConstants;
import com.ruoyi.dataserver.utils.ExcelExportUtils;
import com.ruoyi.dataserver.utils.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @ProjectName intelligent-city
 * @Package com.lab.dataserver.controller
 * @ClassName PipeDiameterAnalysisController
 * @Description 管径分段分析
 * @Company LAB
 * @Author LXK
 * @Date 2020/7/9 14:12
 * @UpdateUser
 * @UpdateDate
 * @UpdateRemark
 * @Version 1.0.0
 */
@RestController
@RequestMapping("/pipe")
@Slf4j
public class PipeDiameterAnalysisController {

    @Autowired
    private ISegmentationService segmentationService;

    @Autowired
    private ScConfigAddress scConfigAddress;

    /** 
     * @Title pipeDiameterSegmentation
     * @Description 管径分段统计
     * @param statisticDto : 
     * @return com.lab.dataserver.utils.R
     * @author Lixk
     * @date 2020/7/13 17:03
     * @UpdateUser 
     * @UpdateDate 
     * @UpdateRemark 
    */
    @PostMapping("/segmentation")
    public R pipeDiameterSegmentation(@RequestBody StatisticDto statisticDto, HttpServletResponse response) throws IOException {
        StatisticResultDTO statisticResultDTO = segmentationService.pipeDiameterSegmentation(statisticDto);
        if(statisticDto.getExport()!=null&&statisticDto.getExport().equals(CommonConstants.EXPORT)) {
            String deviceTemplate = scConfigAddress.getExcelExportFilePath();
            ExcelExportUtils excelExportUtils = new ExcelExportUtils();
            excelExportUtils.lengthUtil(deviceTemplate,statisticResultDTO, response);
        }
        return R.ok(statisticResultDTO,"统计成功");
    }

    /** 
     * @Title pipeSegmentationDeep
     * @Description 埋深分段统计
     * @param statisticDto : 
     * @return com.lab.dataserver.utils.R
     * @author Lixk
     * @date 2020/7/13 17:05
     * @UpdateUser 
     * @UpdateDate 
     * @UpdateRemark 
    */
    @PostMapping("/segmentationDeep")
    public R pipeSegmentationDeep(@RequestBody StatisticDto statisticDto,HttpServletResponse response) throws IOException {
        StatisticResultDTO  statisticResultDTO = segmentationService.pipeSegmentationDeep(statisticDto);
        if(statisticDto.getExport()!=null&&statisticDto.getExport().equals(CommonConstants.EXPORT)) {
            String deviceTemplate = scConfigAddress.getExcelExportFilePath();
            ExcelExportUtils excelExportUtils = new ExcelExportUtils();
            excelExportUtils.lengthUtil(deviceTemplate,statisticResultDTO, response);
        }
        return R.ok(statisticResultDTO,"统计成功");
    }
}
